/**
 * @description: 公共判断登录状态方法
 * @param noPassword 是否设置密码
 * @param realname 是否实名
 * @param funcName 认证成功后调用的函数名称
 * @example: this.donext(){this.$store.dispatch('getGgzyPub')}是否需要调用接口，默认不掉用
 */
import unicore from '@/core/core.service.ts'
export const checkLogin = {
    methods:{
        checkLogin(){
            const noPassword = unicore.util.localStorage.get("noPassword")
            const route = this.$core.dom.window.location.hash.replace(/\#/g,"")
            console.log(route,'<-route')
            if (this.iswxh5) {
                console.log(this.fromno.isBind,'this.fromno.isBind')
                if (this.fromno.isBind=='false') {
                    let url = '/pages/login/indexty?redirect='+ route
                    console.log(url,'url')
                    return uni.navigateTo({url:url})
                }
                if (noPassword) {
                    return uni.navigateTo({url:'/pages/login/passwordty?redirect='+ route})
                }
                this.$store.state.common.token = '123456789'
                // this.$store.state.common.token = ''
                const code = this.$core.dom.getQueryString('code');
                const openid=this.$core.dom.getQueryString('wxOpenId') || unicore.util.localStorage.get("wxOpenId");
                if(openid){
                    this.$core.util.localStorage.set("wxOpenId",openid)
                    this.$store.state.common.wxOpenId = this.$core.util.localStorage.get("wxOpenId");
                }
                console.log(code,'code')
                console.log(openid,'openid')
                if(code!=="" && code !=='0'){
                    uni.redirectTo({
                        url:'/pages/oldClient/verifyFalse'
                    })
                    return ;
                } else if(code ==='0'){
                    this.$store.dispatch("realNameCode").then(res => {
                        this.getIdCard()
                    });
                    return;
                }
                const bizToken = this.$core.dom.getQueryString('bizToken');
                console.log(bizToken,'<-bizToken')
                if(bizToken){
                    this.$store.dispatch("realName",bizToken).then(res => {
                        if(res !== undefined){
                            if(res.reqResult.code == -200000){
                                /**重复认证特殊处理 */
                                uni.redirectTo({url:'/pages/oldClient/verifyFalse2'})
                            }else{
                                /**res解析正常，无报错情况 */
                                this.getIdCard()
                            }
                        }else{
                            /**实名认证有误 */
                            uni.redirectTo({url:'/pages/oldClient/verifyFalse'})
                        }
                        
                    })
                }else {
                    //没有bizToken自动跳转实名！！！
                    console.log(bizToken,'<-NobizToken')
                    this.getIdCard()
                }
            }else{
                if (!this.$store.state.common.token) {
                    this.$store.state.common.saveUrl = route
                    return uni.navigateTo({url:'/pages/login/indexty'})
                }
                console.log(this.$store.state.common.realname,'console.log(this.$store.state.common.realname)')
                if (noPassword) {
                    return uni.redirectTo({url:'/pages/login/passwordty?redirect='+ route})
                }
                if (!this.$store.state.common.realname) {
                    return uni.redirectTo({url:'/pages/uploadId/uploadId'})
                }
                if (this.donext) {
                    this.donext()
                }
            }
        },
        // getIdCard(funcName){
        //     const wxOpenId = unicore.dom.getQueryString("wxOpenId") || unicore.util.localStorage.get("wxOpenId")
        //     this.$store.dispatch('getIdCard').then(res => {
        //         if(res.data && res.data.url){
                    
        //         }else{
        //             if(funcName){
        //                 this.$store.dispatch(funcName)
        //             }
        //             // this.$store.dispatch('getGgzyPub')
        //         }
        //     })
        // },
    }
}